//
//  MenuViewController.m
//  ProJectB_1
//
//  Created by lanou3g on 16/8/12.
//  Copyright © 2016年 yangshukai. All rights reserved.
//

#import "MenuViewController.h"
#import "DrawerViewController.h"
#import "AppDelegate.h"

@interface MenuViewController ()
{
    NSMutableArray *list; // 菜单列表数据源
    AppDelegate *app;
}
@end

@implementation MenuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    list = [[NSMutableArray alloc]init];
    [list addObject:@"视频"];
    [list addObject:@"段子"];
    [list addObject:@"耳边轻语"];
    [list addObject:@"图片"];
    [list addObject:@"收藏列表"];
    [list addObject:@"下载列表"];
    [list addObject:@""];
    
    app = (AppDelegate *)[[UIApplication  sharedApplication] delegate];
    if (!app.yeJianisOn) {
        _yeJianLabel.text = @"白 天";
        
    }else{
        _yeJianLabel.text = @"夜 间";
        
    }
    _yeJian.on = app.yeJianisOn;
}

//改变行的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}
//返回TableView中有多少数据
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [list count];
}
//返回有多少个TableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
//组装每一条的数据
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CustomCellIdentifier =@"CellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
    if (cell ==nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CustomCellIdentifier];
    }
    cell.textLabel.text = [list objectAtIndex:indexPath.row];
    return cell;
}

// 选中Cell响应事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
    // 获取抽屉对象
    DrawerViewController *menuController = (DrawerViewController*)((AppDelegate *)[[UIApplication sharedApplication] delegate]).rootTabBarViewController.drawerController;
    
    if (indexPath.row == 0) {
        ShiPingViewController *VC = [[ShiPingViewController alloc]init];
        UINavigationController *NC = [[UINavigationController alloc]initWithRootViewController:VC];
        [menuController setRootController:NC animated:YES];
        NSLog(@"跳转");
    }else if (indexPath.row == 1){
        DuanZiViewController *vc = [[DuanZiViewController alloc]init];
        UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:vc];
        [menuController setRootController:nc animated:YES];
        
        
        DuanZiViewController *VC = [[DuanZiViewController alloc]init];
        UINavigationController *NC = [[UINavigationController alloc]initWithRootViewController:VC];
        [menuController setRootController:NC animated:YES];
        NSLog(@"跳转");
    }else if (indexPath.row == 2){
        DianTaiViewController *VC = [[DianTaiViewController alloc]init];
        UINavigationController *NC = [[UINavigationController alloc]initWithRootViewController:VC];
        [menuController setRootController:NC animated:YES];
        NSLog(@"跳转");
    }else if (indexPath.row == 3){
        QitaViewController *VC = [[QitaViewController alloc]init];
        UINavigationController *NC = [[UINavigationController alloc]initWithRootViewController:VC];
        [menuController setRootController:NC animated:YES];
        NSLog(@"跳转");
    }else if (indexPath.row == 4){
        LoveListViewController *VC = [[LoveListViewController alloc]init];
        UINavigationController *NC = [[UINavigationController alloc]initWithRootViewController:VC];
        [menuController setRootController:NC animated:YES];
        NSLog(@"跳转");
    }else if (indexPath.row == 5){
        
        
        
    }
  
}
// 设置
- (IBAction)sheZhi:(id)sender {
    
    
    
    
}
// 夜间
- (IBAction)yeJian:(id)sender {
    if (_yeJian.isOn == YES) {
        _yeJianLabel.text = @"夜 间";
        if (app.yeJianView == nil) {
            app.yeJianView = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
            app.yeJianView.backgroundColor = [UIColor blackColor];
            app.yeJianView.alpha = 0.5;
            app.yeJianView.userInteractionEnabled = NO;
        }
        [[[UIApplication sharedApplication] delegate].window addSubview:app.yeJianView];
    }else{
        _yeJianLabel.text = @"白 天";
        if (app.yeJianView != nil) {
            [((AppDelegate *)[[UIApplication sharedApplication] delegate]).yeJianView removeFromSuperview];
            ((AppDelegate *)[[UIApplication sharedApplication] delegate]).yeJianView = nil;
        }
    }
    app.yeJianisOn = _yeJian.isOn;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
